package pers.richard.ormybatis.bean;

import java.io.Serializable;
import java.util.Map;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.builder.EqualsBuilder;
import cn.hutool.core.builder.HashCodeBuilder;

/**
 * 基础java domain
 */
public class AbstractDomain implements Serializable {

	@Override
	public int hashCode() {
		return HashCodeBuilder.reflectionHashCode(this);
	}

	@Override
	public boolean equals(Object obj) {
		return EqualsBuilder.reflectionEquals(this, obj);
	}

	@Override
	public String toString() {
		return this.getClass().getSimpleName() + ":" + this.toMap().toString();
	}

	/**
	 *	转成map形式
	 */
	public Map<String, Object> toMap() {
		return BeanUtil.beanToMap(this);
	}

	/**
	 *	转成map形式 key变成 lower_underscore的下划线形式
	 */
	public Map<String, Object> toMapKeyToUnderscore() {
		return BeanUtil.beanToMap(this, true, false);
	}
	
}